#元素定位
from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By

from options import options

url=r'https://www.baidu.com'
driver=webdriver.Chrome(options=options)
driver.get(url)

# #1.id定位:首选
# driver.find_element(By.ID,'kw').send_keys('selenium')
# driver.find_element(By.ID,'su').click()
# sleep(3)
#
# #2、name定位：次选
# driver.find_element(By.NAME,'wd').send_keys('selenium2')
# driver.find_element(By.ID,'su').click()
# sleep(3)
#
# #3、tag定位：了解
# driver.find_elements(By.TAG_NAME,'input')[7].send_keys('s3')
# driver.find_elements(By.TAG_NAME,'input')[8].click()
# sleep(3)
#
# #4、class定位，适合定位class为单属性的元素
# driver.find_element(By.CLASS_NAME,'s_ipt').send_keys('s4')
# driver.find_element(By.CLASS_NAME,'').click()
# sleep(3)

#5、xpath定位
'''
xpath基本语法
/       根路径
//      相对路径
*       所有标签
input   指定标签
[@id="kw"] 指定属性

'''
# #5-1绝对路径——无法使用，绝对路径有错
# driver.find_element(By.XPATH,'/html/body/div[2]/div[1]/div[5]/div/div/form/span[1]/input').send_keys('s5')
# driver.find_element(By.XPATH,'/html/body/div[2]/div[1]/div[5]/div/div/form/span[2]/input').click()
# sleep(3)

#5-2相对路径
driver.find_element(By.XPATH,'//*[@id="kw"]').send_keys('s6')
driver.find_element(By.XPATH,'//*[@id="su"]').click()
sleep(3)

#5-3相对路径之指定标签
driver.find_element(By.XPATH,'//input[@id="kw"]').send_keys('s7')
driver.find_element(By.XPATH,'//input[@id="su"]').click()
sleep(3)
#5-4相对路径之指定上层元素路径




